﻿using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using 无人值守地磅称重系统.Models.Menu;
using 无人值守地磅称重系统.ViewModels;

namespace 无人值守地磅称重系统.Views
{
    /// <summary>
    /// MainView.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : UserControl
    {
        public MainView()
        {
            InitializeComponent();
            DataContext = App.Current.Services.GetService<MainViewModel>();
            // 默认页面
            //page.Content = App.Current.Services.GetService<IndexView>();
            page.Content = App.Current.Services.GetService<TestView>();
            // 切换页面
            WeakReferenceMessenger.Default.Register<MenuEntity>(this, (sender, arg) => { 
                Assembly assembly= Assembly.GetExecutingAssembly();
                var type = assembly.GetType($"{assembly.GetName().Name}.Views.{arg.View}");
                page.Content = App.Current.Services.GetService(type);
            });
        }
    }
}
